#include "timestamp.h"

uint32_t MakeTimestamp(TimeFormat_t *pTransitionTimeIn)
{
  struct tm Information = {0};

  Information.tm_year = pTransitionTimeIn->Year - 1900;
  Information.tm_mon = pTransitionTimeIn->Month - 1;
  Information.tm_mday = pTransitionTimeIn->Date;
  Information.tm_hour = pTransitionTimeIn->Hour;
  Information.tm_min = pTransitionTimeIn->Minute;
  Information.tm_sec = pTransitionTimeIn->Second;

  return mktime(&Information);
}

void TimestampToNormalTime(uint32_t UtcSecond, TimeFormat_t *pTransitionTimeOut)
{
  if (pTransitionTimeOut != NULL)
  {
    time_t Time = UtcSecond;
    struct tm Information = {0};

    Information = *localtime(&Time);
    pTransitionTimeOut->Year = Information.tm_year + 1900;
    pTransitionTimeOut->Month = Information.tm_mon + 1;
    pTransitionTimeOut->Date = Information.tm_mday;
    pTransitionTimeOut->Week = Information.tm_wday;
    pTransitionTimeOut->Hour = Information.tm_hour;
    pTransitionTimeOut->Minute = Information.tm_min;
    pTransitionTimeOut->Second = Information.tm_sec;
  }
}
